package com.lishe.lishe.lishe.ImageSelector;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListAdapter;

import com.lishe.lishe.Imageloader.ImageLoaderUtils;
import com.lishe.lishe.R;
import com.lishe.lishe.lishe.utils.FileObject;

import java.io.IOException;
import java.util.LinkedList;

import static android.R.attr.bitmap;
import static android.R.attr.pointerIcon;

/**
 * Created by shino on 2017/10/19.
 */

public class ImageAdapter extends BaseAdapter {
    private LinkedList<ImageObject> images;
    private Context context;
    private ImageLoaderUtils imageLoaderUtils;

    public ImageAdapter(Context context, LinkedList<ImageObject> images) {
        this.context = context;
        this.images = images;
        imageLoaderUtils = new ImageLoaderUtils();
    }

    @Override
    public int getCount() {
        return images == null ? 0 : images.size();
    }

    @Override
    public Object getItem(int i) {
        return images.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if (view == null) {
            view = View.inflate(context, R.layout.item_image_selector, null);
            viewHolder = new ViewHolder(view);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        if (images.get(i).isCheck()) {
            viewHolder.select_icon.setImageResource(R.mipmap.sel_choice_icon);
        } else {
            viewHolder.select_icon.setImageResource(R.mipmap.circle_white_icon);
        }
        imageLoaderUtils.displayLocationImage(images.get(i).getPath(), viewHolder.image);
//        viewHolder.image.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                images.get(i).setCheck(!images.get(i).isCheck());
//                notifyDataSetChanged();
//            }
//        });
        return view;
    }

    public class ViewHolder {
        public ImageView image;
        public ImageView select_icon;

        ViewHolder(View v) {
            image = v.findViewById(R.id.img);
            select_icon = v.findViewById(R.id.select_icon);
        }
    }
}
